
function SetCameraState(a)
{
	flashpoint();

	printf('# for most parameter tags');
	printf('# can run SetCameraState(param,...)');
	printf('# select from the listings (a-z)');
	printf('# select the parameter tag ');
	printf('# exit the script, and check the camera ');
	printf('# to see if it was successfull');
	
	var alphaNum = new Array();		// associate a number with each alpha character

	var usetVar=new Array("uset0","uset1","uset2","uset3","uset4","uset5","uset6","uset7" );
	var isetVar=new Array("iset0","iset1","iset2","iset3","iset4","iset5","iset6","iset7" );
	var ssetVar=new Array("sset0","sset1","sset2","sset3","sset4","sset5","sset6","sset7" );
	
	var setTitle=new Array("title0","title1","title2","title3","title4","title5","title6","title7" );

	var i,setting,achar,count;
	
	writeMenu('"SetCameraState"','"EXTRA"','"SCStateOption"');
	writeVariables();
	printf('declare s: readwrite ');

	print('declare u: uset0');
	for(i=1 ;i< usetVar.length ; i++) print(",",usetVar[i]); printf(' ');
	print('declare i: iset0');
	for(i=1 ;i< isetVar.length ; i++) print(",",isetVar[i]); printf(' ');
	print('declare s: sset0');
	for(i=1 ;i< ssetVar.length ; i++) print(",",ssetVar[i]); printf(' ');

	print('declare s: title0');	
	for(i=1 ;i< setTitle.length ; i++) print(",",setTitle[i]); printf(' ');

	printf('declare u: doit,countSetting');
	
	printf('<br>','#**** OPEN FILE ****');
  	printf('outFile="/System/ZSState.txt"');
	writeFileOpen();


	/*
	 * MENU 1 
	 * for each alphabetic character(a,b,c....z) write a SetOption
	 * but only for one that's used
	 * user selects first character of parameter tag (i.e. a for acpd )
	 */
	 
	achar=" ";		// start with a blank
	count=1;
	printf('LOOP:');
	printf('DisplayClear()');
	for( i=1; i<a.length ; i++)
	if( a[i].param.substring(1,2) != achar  ){
			achar=a[i].param.substring(1,2);					// save the first character
			alphaNum[ a[i].param.substring(1,2) ] = count;		// and count associated with this char
			printf('SetOption(',count,',"',achar , '",0)' );	// do the SetOption stuff
			count++;	
	} 
	printf('GetOption(choice)');
	

	/*
	 * MENU 2
	 * place all tags starting with 'a' together in one option list
	 * do the same for 'b', 'c', etc,..
	 * example "deft", "dfmt", "drdn" will all be in the same menu list
	 */	 

	achar=" ";		// start with a blank
	count=0;	
	
	for( i=1; i<a.length ; i++){
	
//	if( a[i].host == "Read") continue;

	if( a[i].param.substring(1,2) != achar )
	{
			// finished off previous option list
			if( i!=1){
					printf('GetOption(choice2)');	
					printf('end<br>');
			}

 			count++;			
			printf('if choice == ',alphaNum[ a[i].param.substring(1,2) ] );		// get count value
			printf('SetOption(500,"Quit",1)');
											
			achar=a[i].param.substring(1,2);												
	}	
				
		printf('SetOption(',i,",",a[i].param,',0)' );
	}// end of for loop 

	// the last one has to have this, a hack, sorry.......
	printf('GetOption(choice2)');	
	printf('end');


/* MENU 3 (lowest layer)
 * This one has ONE parameter tag per if ...SetOption() ... end set
 * the number of options availalble depends on the parameter tag	
 * list available settings for each parameter
 # min-max type:   min,max
 # enum type:	    available enum settings
 * simple type:    default?
 */
 
  	printf(' ');
  	printf( 'theType = "UInt" ' );

  	/* 
  	 * Generate a series of
  	 *  if <   >
  	    SetOption()
  	    ....
  	    GetOption()  	    
  	    end
  	 * Each if ... end set represents a single parameter tag and its possible values
	 * type should be either Enum, UInt, String or Fixed ...
	 */
	for(i=1 ; i<a.length ; i++){
 		
 		
		// an EnumList or EnumListHex type
		if( a[i].type.substring(0,4) == "Enum" ){
 		printf(' ');
		
 		printf('<br>if choice2 == ',i  );
		printf('param = ',a[i].param );
//		printf('theType="Enum"');
		
				found=0;
 				for( theType in  a[i]   ){	
 						
						if( paramNotThere( theType , parameterTag) ){
								found=1;
								theName=theType+"(" + a[i][theType] + ")";
								printf('SetOption(',a[i][theType],',"',theName,'", 0)' );
								
						}
				}
				
		if(found)
		printf('GetOption(choice3)' );
		printf('end');
		}// end of EnumList ***********************************************************
		
		
		// an Fixed or BitMask type
		if( (a[i].type=="Fixed") || (a[i].type=="BitMask")){
		found=0;
 		printf(' ');
		
 		printf('<br>if choice2 == ',i  );
		printf('param = ',a[i].param );
//		printf('theType= ',a[i].type );
			// guard against a string ( Netscape 3 problem )
		 	if (  (typeof(a[i].max)=="string") || (a[i].max != 0 )  ){

						found=1;
						index=1;
						printf('SetOption(',a[i].min,',"',a[i].min,'", 0)' );
						printf('SetOption(',a[i].max,',"',a[i].max,'", 0)' );

			}// end of max if
		
		// check for  an added parameter to test( just for QA purposes)
		 				for( theType in  a[i]   ){	
						if( paramNotThere( theType , parameterTag) ){
		 						found=1;						
								printf('SetOption(',a[i][theType],',"',a[i][theType],'", 0)' );
						}
			}
	
			if( found )
			printf('GetOption(choice3)' );
	
			if( a[i].host=="Read"){
					printf('Alert("READ only")');
					printf('goto LOOP');
					
			}
		
		printf('end');
		
		}// end of Fixed, BitMask case *************************************************************
		
		// an UInt type
		if( a[i].type=="UInt" ){
		found=0;
 		printf(' ');
		
 		printf('<br>if choice2 == ',i  );
		printf('param = ',a[i].param );
			if( a[i].max != 0){
						found=1;
						theName="min(" + a[i].min + ")";			
						printf('SetOption(',a[i].min,',','"',theName,'"',', 0)' );

						theName="max(" + a[i].max + ")";						
						printf('SetOption(',a[i].max,',','"',theName,'"', ', 0)' );
						

			}// end of max if
		
		// check for  an added parameter to test( just for QA purposes)
		 				for( theType in  a[i]   ){	
						if( paramNotThere( theType , parameterTag) ){
 								found=1;						
								theName=theType+"(" + a[i][theType] + ")";
								printf('SetOption(',a[i][theType],',"',theName,'", 0)' );
								
						}
			}
	
			if( found )
			printf('GetOption(choice3)' );
	
			if( a[i].host=="Read"){
					printf('Alert("READ only")');
					printf('goto LOOP');
					
			}
		
		printf('end');
		
		}// end of UInt case *************************************************************
				
		
		// a String, probably camera name
		if( a[i].type=="String" ){
		found=0;
		 	printf('<br>if choice2 == ',i  );
			printf('param = ',a[i].param );
			printf('theType= "String"' );

			if( a[i].host=="Read"){
					printf('Alert("READ only")');
					printf('goto LOOP');
					
			}else{
				found=1;
				index=1;

				if(index==1) printf('svar=',a[i].def);						
				printf('SetOption(',index++,',',a[i].def,', 0)' );
				

						// check for  an added parameter to test( just for QA purposes)
		 				for( theType in  a[i]   )
 						if( paramNotThere( theType , parameterTag) ){
//								if(index==2) printf('svar2=',a[i].def);
//								if(index==3) printf('svar3=',a[i].def);
//								if(index==4) printf('svar4=',a[i].def);						
								printf('SetOption(',index++,',"',a[i][theType],'", 0)' );
								
						}
			}
																				
		if( found )
			printf('GetOption(choice3)' );
		
		printf('end');
		
		}// end of String case ************************************************************

 	}// end of for loop
 
 	printf( 'if theType != "String" ' );
 	printf('status=SetCameraState(param,choice3)');
 	printf('DisplayLine(param,"[",status,"]" )' );
 	printf('Wait(2000)');
 	printf('end');
 	printf(' ');
 	
 	printf( 'if theType == "String" ' );
 	printf('status=SetCameraState(param,svar)');
 	printf('DisplayLine(param,"[",status,"]" )' );
 	printf('Wait(2000)');
 	printf('end ');
 	

	printf('if choice2 != 500');
	printf('goto LOOP');
	printf('end');
	
	writeFileClose();
	printf('exitscript');

}

